{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[6, 9, 6],\n",
       "       [1, 1, 2],\n",
       "       [8, 7, 3],\n",
       "       [5, 6, 3],\n",
       "       [5, 3, 5],\n",
       "       [8, 8, 2],\n",
       "       [8, 1, 7],\n",
       "       [8, 7, 2],\n",
       "       [1, 2, 9],\n",
       "       [9, 4, 9]])"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.seed(1)\n",
    "X=np.random.randint(1,10,size=30)\n",
    "\n",
    "Y=X.reshape(-1,3)\n",
    "Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 9, 1],\n",
       "       [1, 1, 0],\n",
       "       [8, 7, 0],\n",
       "       [5, 6, 0],\n",
       "       [5, 3, 1],\n",
       "       [8, 8, 0],\n",
       "       [8, 1, 2],\n",
       "       [8, 7, 0],\n",
       "       [1, 2, 2],\n",
       "       [9, 4, 2]])"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ser=pd.Series(X,index=list(range(1,31)))\n",
    "\n",
    "for i in range(1,32):\n",
    "    if i %3==0:\n",
    "        if ser[i]<=3 :\n",
    "            ser[i]=0\n",
    "        elif ser[i]>6:\n",
    "            ser[i]=2\n",
    "        else:\n",
    "            ser[i]=1\n",
    "    ser2=ser.values.reshape(-1,3)\n",
    "ser2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "特征值为0：\n",
      " [[1. 1.]\n",
      " [8. 7.]\n",
      " [5. 6.]\n",
      " [8. 8.]\n",
      " [8. 7.]]\n",
      "特征值为1：\n",
      " [[6. 9.]\n",
      " [5. 3.]]\n",
      "特征值为2：\n",
      " [[8. 1.]\n",
      " [1. 2.]\n",
      " [9. 4.]]\n"
     ]
    }
   ],
   "source": [
    "X_train=ser2[::,0:2]\n",
    "y_train=ser2[::,2:3:3]\n",
    "\n",
    "\n",
    "s1,s2,s3=[],[],[]\n",
    "for i in range(0,10):\n",
    "    \n",
    "    if y_train[i]==[0]:\n",
    "        a1=X_train[i]\n",
    "        s1=np.concatenate([s1,a1],axis=0)\n",
    "    if y_train[i]==[1]:\n",
    "        a2=X_train[i]\n",
    "        s2=np.concatenate([s2,a2],axis=0)\n",
    "    if y_train[i]==[2]:\n",
    "        a3=X_train[i]\n",
    "        s3=np.concatenate([s3,a3],axis=0)\n",
    "\n",
    "\n",
    "print(\"特征值为0：\\n\",s1.reshape(-1,2))\n",
    "print(\"特征值为1：\\n\",s2.reshape(-1,2))\n",
    "print(\"特征值为2：\\n\",s3.reshape(-1,2))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
